package pc2brick;
import lejos.nxt.*;

// stop when touched or less than 10 centimeters
public class swt 
{
	public static void main(String[] args) throws Exception 
	{
		TouchSensor touch = new TouchSensor(SensorPort.S1);
		UltrasonicSensor sonic = new UltrasonicSensor(SensorPort.S2);
		int distance;
		
		while(!touch.isPressed())
		{
			distance = sonic.getDistance();
			LCD.clear();
			LCD.drawInt(distance, 0, 0);
			
			if (distance > 10)
			{
				LCD.drawString("avance", 0, 1);
				Motor.A.forward();
				Motor.B.forward();
				Motor.C.forward();
				//Motor.B.forward();
			}else{
				Motor.A.stop();
				Motor.B.stop();
				Motor.C.stop();
				LCD.drawString("stop", 0, 1);
			}
		}
	}
}
